<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="/views/common/header.jsp" %>

<div class="box box-primary">
  <div class="box-header with-border">
  </div><!-- /.box-header -->
  <!-- form start -->
  <form role="form" id="form-cate">
    <div class="box-body">
      <div class="form-group">
        <input type="hidden" value="${res_type.id }" name="id" id="id">
        <label>父栏目</label>
        <select class="form-control" name="parent">
          <option value="0">作为一级栏目</option>
          <c:forEach var="type" items="${type_list}">
          <option value="${type.id }" <c:if test="${type.id == res_type.id}"></c:if>>${type.name }</option>
          </c:forEach>
        </select>
      </div>
      <div class="form-group">
        <label for="exampleInputPassword1">类型名称</label>
        <input type="text" class="form-control" id="name" name="name" value="${res_type.name }" placeholder="类型名称">
      </div>
    </div><!-- /.box-body -->

    <div class="box-footer">
      <button type="button" id="btn-submit" class="btn btn-primary">保存</button>
    </div>
  </form>
</div>
<script>
$(function (){
	$('#btn-submit').on('click', function (){
		var data = $('#form-cate').serialize()
		$.ajax({
			'data': data,
			'url': '/restype/save',
			'dataType': 'JSON',
			'success': function (ret){
				switch (ret.code)
				{
				case 200:
				case '200':
					window.location.href = '/restype/list'
					break
				default:
					swal('保存失败', ret.msg, 'error');
			        break
				}
			},
			'error': function (ret){
				swal('保存失败', '', 'error');
			}
		})
	});
})
</script>

<%@ include file="/views/common/footer.jsp" %>